package com.molyfun.parents.activity.report.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.attachment.AttachmentViewer;
import com.molyfun.parents.rest.bean.MediaobjectlistBean;
import com.molyfun.parents.rest.bean.PlanDetailCallListViewResponse;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Administrator on 2017/12/21 0021.
 */

public class PlanDetailCallListCotentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>  {
    Context mContext;
    private List<PlanDetailCallListViewResponse.PlanDetailTargetList.RecordsBean>  mList;

    private int mCurrentTab = 0;



    public PlanDetailCallListCotentAdapter(Context context) {
        this.mContext = context;

    }

    public void refreshData(List<PlanDetailCallListViewResponse.PlanDetailTargetList.RecordsBean> list) {
        this.mList = list;
        notifyDataSetChanged();
    }


    public void clearAll(){
        if(mList != null){
            mList.clear();
            notifyDataSetChanged();
        }
    }

    public void addAll(List<PlanDetailCallListViewResponse.PlanDetailTargetList.RecordsBean> list) {
        this.mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new PlanDetailCallListCotentViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_plan_detail_single_cell, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        PlanDetailCallListViewResponse.PlanDetailTargetList.RecordsBean recordsBean = mList.get(position);
        final PlanDetailCallListCotentViewHolder planBriefViewHolder = (PlanDetailCallListCotentViewHolder)holder;
        planBriefViewHolder.mPlanDetailSingleTitle.setText(recordsBean.getTargettraining());
        List<? extends MediaobjectlistBean> mediaobjectlist = recordsBean.getMediaobjectlist();
        if(mediaobjectlist != null && mediaobjectlist.size()>0) {
            for(int i = 0;i<mediaobjectlist.size();i++) {
                mediaobjectlist.get(i).setType(1);
            }
            planBriefViewHolder.mAttachment_viewer.setVisibility(View.VISIBLE);
            planBriefViewHolder.mAttachment_viewer.initData(mediaobjectlist);
        }else {
            planBriefViewHolder.mAttachment_viewer.setVisibility(View.GONE);
        }
//
//        if(mCurrentTab == position){
//            planBriefViewHolder.itemView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_bg));
//        }else{
//            planBriefViewHolder.itemView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_transparent));
//        }

    }



    public class PlanDetailCallListCotentViewHolder extends RecyclerView.ViewHolder {

        @InjectView(R.id.plan_detail_single_cell_title)
        TextView mPlanDetailSingleTitle;
        @InjectView(R.id.attachment_viewer)
        AttachmentViewer mAttachment_viewer;

        public PlanDetailCallListCotentViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }

    @Override
    public int getItemCount() {
        if (mList == null || mList.size() == 0) {
            return 0;
        }
        return mList.size();
    }

}
